<template>
  <div class="smart-table">
    <el-table ref="table"
      :data="list"
      style="width: 100%;"
      :max-height="maxHeight"
      v-loading="tableLoading"
      border
    >
      <el-table-column v-if="selectable" type="selection" width="60" align="center"></el-table-column>
      <el-table-column v-for="(item, index) in columns" :key="index" :label="item.label" :width="item.width" align="center">
        <template slot-scope="scope">{{scope.row.brandCode}}</template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @size-change="sizeChange"
        @current-change="pageChange"
        layout="total, sizes, prev, pager, next, jumper"
        :current-page.sync="pageNo"
        :page-size="pageSize"
        :page-sizes="sizeArray"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    columns: {
      type: Array,
      default: () => [

      ],
    },
    list: {
      type: Array,
      default: () => [],
    },
    total: {
      type: Number,
      default: 0,
    },
    // 是否可以全选
    selectable: {
      type: Boolean,
      default: false,
    },
    // 最大高度
    maxHeight: {
      type: Number,
      default: null,
    },
  },
  data () {
    return {
      sizeArray: [5, 10, 15],
      pageNo: 0,
      pageSize: 10,
      tableLoading: false,
    }
  },
  watch: {
    loading (val) {
      this.tableLoading = val
    },
  },
  mounted () {
    // 动态设置table高度
  },
  methods: {
    sizeChange (val) {
      this.pageSize = val
      this.pageNo = 1
      this.$emit('query', this.pageNo, this.pageSize)
    },
    pageChange (val) {
      this.pageNo = val
      this.$emit('query', this.pageNo, this.pageSize)
    },

  },
}
</script>